package com.springcloud.service.Impl;

import com.springcloud.dao.LoginMsgDao;
import com.springcloud.entities.LoginMsg;
import com.springcloud.service.IMessageConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class MessageConsumerImpl implements IMessageConsumer {
    private static final Logger logger = LoggerFactory.getLogger(MessageConsumerImpl.class);
    @Resource
    private LoginMsgDao loginMsgDao;
    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public int save(String loginName) {
        LoginMsg msg=new LoginMsg();
        msg.setLoginName(loginName);
        msg.setStatus(1);
        msg.setCreateTime(new Date());
        int rs=loginMsgDao.save(msg);
        LoginMsg save = mongoTemplate.save(msg);
        logger.debug(save.toString());
        return rs;
    }
}
